<?php

namespace backend\models;
use yii\behaviors\TimestampBehavior;
use Yii;

/**
 * This is the model class for table "{{%jjr_user}}".
 *
 * @property string $id
 * @property string $openid 第三方id
 * @property string $mobile 手机号码
 * @property string $real_name 真实姓名
 * @property string $nick_name 昵称
 * @property string $password
 * @property string $avatar_url
 * @property int $gender
 * @property int $identity 身份类型
 * @property string $create_time
 * @property string $update_time
 * @property int $status
 * @property int $is_sender 需求发布者权限 3:未申请过1：审核中/2：审核通过/0：未通过
 * @property string $sender_remark 经纪人不通过理由
 * @property string $idcard 身份证
 * @property  int $fuid 推荐人
 * @property  string $invite_code 邀请码
 */
class JjrUser extends \common\core\BaseActiveRecord
{
    const IDENTITY_FREE=1; //大众经纪人
    const IDENTITY_COMPANY=2; //公司经纪人
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%jjr_user}}';
    }
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    # 创建之前
                    \yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
                    # 修改之前
                    \yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time']
                ],
                #设置默认值
                'value' =>date('Y-m-d H:i:s')
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['openid', 'real_name','mobile','idcard','gender', 'identity'], 'required'],
            [['gender', 'identity', 'status', 'is_sender','fuid'], 'integer'],
            ['gender','in','range' => [1, 2],'message'=>'性别格式不正常'],
            [['create_time', 'update_time','idcard'], 'safe'],
            [['openid', 'real_name', 'nick_name', 'password', 'avatar_url', 'sender_remark','invite_code'], 'string', 'max' => 255],
            [['mobile'], 'string', 'max' => 11],
            [['idcard'], 'string', 'max' => 50],
            ['mobile', 'required'],
           // ['openid', 'unique','message' => 'openid已绑定'],
            ['mobile', 'filter', 'filter' => 'trim'],
            ['mobile','match','pattern'=>'/^[1][3456789][0-9]{9}$/'],
            ['mobile', 'unique', 'message' => '手机号已被使用'],

        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'openid' => '第三方id',
            'mobile' => '手机号码',
            'idcard'=>'身份证',
            'real_name' => '真实姓名',
            'nick_name' => '昵称',
            'password' => '密码',
            'avatar_url' => '头像',
            'gender' => '性别',
            'identity' => '身份类型',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
            'status' => '状态',
            'is_sender' => '需求发布者权限 3:未申请过1：审核中/2：审核通过/0：未通过',
            'sender_remark' => '经纪人不通过理由',
            'fuid'=>'推荐人',
            'invite_code'=>'邀请码'
        ];
    }
}
